package com.aoxun.core.redis;

import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * <pre>
 * 默认缓存业务实现类
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2017年12月6日 下午2:06:04
 * @since 1.0
 */
@Service
public class RedisServiceImpl implements RedisService {

	@Resource
	private StringRedisTemplate stringRedisTemplate;

	@Override
	public void addKeyValue(String key, String value) {
		stringRedisTemplate.opsForValue().set(key, value);
	}

	@Override
	public void addKeyValue(String key, String value, int timeout) {
		stringRedisTemplate.opsForValue().set(key, value, timeout, TimeUnit.SECONDS);
	}

	@Override
	public String getValue(String key) {
		return stringRedisTemplate.opsForValue().get(key);
	}

	@Override
	public void deleteValue(String key) {
		stringRedisTemplate.delete(key);
	}

}
